/* voom.h
** 
** Copyright (c) 2007, Homebrew Mobile Phone Club
** All rights reserved.
** 
** Redistribution  and  use  in  source  and  binary  forms,  with  or  without
** modification, are permitted provided that the following conditions are met:
** 
**  * Redistributions of  source code must  retain the above  copyright notice,
**    this list of conditions and the following disclaimer.
** 
**  * Redistributions in binary form must reproduce the above copyright notice,
**    this list of conditions and the following disclaimer in the documentation
**    and/or other materials provided with the distribution.
** 
**  * Neither the name  of the Homebrew Mobile Phone Club nor  the names of its
**    contributors may be used to endorse or promote products derived from this
**    software without specific prior written permission.
** 
** THIS SOFTWARE IS PROVIDED BY  THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY  EXPRESS OR IMPLIED WARRANTIES,  INCLUDING, BUT NOT  LIMITED TO, THE
** IMPLIED WARRANTIES  OF MERCHANTABILITY AND FITNESS FOR  A PARTICULAR PURPOSE
** ARE DISCLAIMED.  IN NO  EVENT SHALL THE  COPYRIGHT OWNER OR  CONTRIBUTORS BE
** LIABLE  FOR  ANY  DIRECT,   INDIRECT,  INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR
** CONSEQUENTIAL  DAMAGES  (INCLUDING,  BUT  NOT  LIMITED  TO,  PROCUREMENT  OF
** SUBSTITUTE GOODS  OR SERVICES;  LOSS OF USE,  DATA, OR PROFITS;  OR BUSINESS
** INTERRUPTION)  HOWEVER CAUSED  AND ON  ANY THEORY  OF LIABILITY,  WHETHER IN
** CONTRACT,  STRICT LIABILITY,  OR  TORT (INCLUDING  NEGLIGENCE OR  OTHERWISE)
** ARISING IN ANY WAY  OUT OF THE USE OF THIS SOFTWARE,  EVEN IF ADVISED OF THE
** POSSIBILITY OF SUCH DAMAGE.
** 
** $Id: voom.h 12 2007-11-07 21:58:17Z msh.mobile $
*/

/* Macro Definitions */
#ifndef _H_VOOM
#define _H_VOOM

/* If we define VOOM_KERNEL, then we define a few macros that are used for
** housekeeping in the voom code.
*/

#ifdef VOOM_KERNEL
#  define VOOM_ENTER tVoomErr err = VOOM_E_NOERR
#  define VOOM_BEGIN do
#  define VOOM_NULLCHECK(o,t) if( NULL == (t)o ) { err = VOOM_E_NULL; break; }
#  define VOOM_END   while( 0 )
#  define VOOM_EXIT  return( err );
#endif /* VOOM_KERNEL */

/* File Includes */

/* If we define VOOM_KERNEL, it means we assume we have a config.h and it's
** an error if it doesn't exist. If we haven't defined VOOM_KERNEL, then it's
** not an error if HAVE_CONFIG_H isn't set, and we assume we have standard
** include files like string.h and stdint.h and the user will define things
** like WORDS_BIGENDIAN.
*/

#ifdef VOOM_KERNEL
#  ifdef HAVE_CONFIG_H
#    include "config.h"
#  else
#    error __FILE__ requires a valid config.h file
#  endif /* HAVE_CONFIG_H */
#else
#  ifdef HAVE_CONFIG_H
#    include "config.h"
#  else
     /* Define Reasonable Defaults */
#    define HAVE_ARPA_INET_H
#    define HAVE_MALLOC_H
#    define HAVE_MEMORY_H
#    define HAVE_STDINT_H
#    define HAVE_STDLIB_H
#    define HAVE_STRING_H
#    define HAVE_UNISTD_H
#  endif /* HAVE_CONFIG_H */
#endif /* VOOM_KERNEL */

#if( HAVE_STDLIB_H == 1 )
#include "stdlib.h"
#endif

#if( HAVE_STDINT_H == 1 )
#include "stdint.h"
#endif

#if( HAVE_STRING_H == 1 )
#include "string.h"
#endif

#if( HAVE_STDIO_H == 1 )
#include "stdio.h"
#endif

#if( HAVE_MEMORY_H == 1 )
#include "memory.h"
#endif

#if( HAVE_MALLOC_H == 1 )
#include "memory.h"
#endif

/* Typedefs, Structs, Unions, Enums, etc. */
typedef enum {
  VOOM_E_NOERR = 0,
  VOOM_E_USAGE,
  VOOM_E_MALLOC,
  VOOM_E_FILE,
  VOOM_E_NULL,
  VOOM_E_UNIMPL,
  VOOM_E_UNKNOWN,
  VOOM_E_MAX
} tVoomErr;

typedef enum {
  VOOM_T_ENDUNKNOWN = 0,
  VOOM_T_ENDBIG,
  VOOM_T_ENDLITTLE
} tVoomEndianness;

typedef struct {
  int             argc;
  char            **argv;
  uint32_t       allocated;
  tVoomEndianness fromConfig;
  tVoomEndianness fromTest;
  uint32_t       charsize;
  uint32_t       shortsize;
  uint32_t       intsize;
  uint32_t       longsize;
  uint32_t       longlongsize;
} tVoomApp;
  
/* Function Prototypes */

tVoomErr voom_init( tVoomApp **app, int argc, char **argv );
tVoomErr voom_print( tVoomApp *app );
tVoomErr voom_deinit( tVoomApp *app );
tVoomErr voom_error( tVoomApp *app, tVoomErr err );

/* External Variable Declarations */

#endif /* _H_VOOM */

